package org.bite.lesson10;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

public class Demo1001 {
    public static void main(String[] args) throws InterruptedException {
        //基于CAS的原子类 解决线程安全问题
        AtomicInteger atomicInteger = new AtomicInteger();

        //创建两个线程 分别自增
        Thread t1= new Thread(()->{
            //自增
            for(int i = 0; i < 5000; i++){
                //自增
                atomicInteger.getAndIncrement();
            }

        });
        t1.start();

        Thread t2= new Thread(()->{
            //自增
            for(int i = 0; i < 5000; i++){
                atomicInteger.getAndIncrement();
            }
        });
        t2.start();

        t1.join();
        t2.join();
        //通过get方法获取atomicInteger对象的值
        System.out.println(atomicInteger.get());

        //一个随机字符串
        System.out.println(UUID.randomUUID());
    }
}
